package com.csx.micrometer.common.config;

import cn.hutool.core.util.ObjectUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;

/**
 * 微服务定位
 * @author cuisongxu
 * @date 2023/2/10 15:16
 */
@Data
@ConfigurationProperties(prefix = MicrometerCoordinateProperties.PREFIX)
public class MicrometerCoordinateProperties {

    public static final String PREFIX = "micrometer.cloud.instance";

    private final Environment environment;

    public MicrometerCoordinateProperties(Environment environment) {
        this.environment = environment;
    }

    /**
     * 区域(一般代表城市)
     */
    private String region;

    /**
     * 可用区(机房)
     */
    private String zoneId;

    /**
     * 单元
     */
    private String unitId;

    /**
     * 系统
     */
    private String systemId;

    /**
     * 环境
     */
    private String envId;

    /**
     * 应用
     */
    private String application;

    public String getApplication() {
        if(ObjectUtil.isEmpty(application)) {
            application = environment.getProperty("spring.application.name");
        }
        return application;
    }
}
